<template>
  <div class="select-box">
    <div>
      <span>机构</span>
      <el-select v-model="value" clearable placeholder="全部" @change="organizationChange" size="small">
        <el-option v-for="item in organization" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
    </div>
    <div>
      <span>医生团队</span>
      <el-select v-model="value1" clearable placeholder="全部" @change="doctorsTeamChange" size="small">
        <el-option v-for="items in doctorsTeam" :key="items.id" :label="items.name" :value="items" />
      </el-select>
    </div>
    <div>
      <span>医生</span>
      <el-select v-model="value2" clearable placeholder="全部" size="small" @change="getdoctorId">
        <el-option v-for="item in doctorsLists" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
    </div>
  </div>
</template>

<script lang='ts' setup>
import { ref } from 'vue';
import api from '../../api';
const value = ref('')
const value1 = ref('')
const value2 = ref('')
// const emit = defineEmits<{ (e: "teamId", val: string): void }>()
//机构
let organization = ref()
//团队
let doctorsTeam = ref()
let doctorsTeamName = ref("")
//医生
let doctorsLists = ref()
//获取机构
const postAllChcsOrgan = async () => {
  const result = await api.Mdatastatistics.postAllChcsOrganApi()
  // console.log('机构', result.data.data.rows);
  organization.value = (result.data.data.rows)
}
postAllChcsOrgan()
//获取机构id
const organizationChange = (val: string) => {
  value1.value = ''
  value2.value = ''
  // console.log('vai', val);
  postTeamByOrganId(val)
}
//获取医生团队
const postTeamByOrganId = async (organId: any) => {
  const result = await api.Mdatastatistics.postTeamByOrganIdApi(organId)
  // console.log("团队", result.data.data);
  doctorsTeam.value = result.data.data

}
//获取医生团队Id
const doctorsTeamChange = (val: any) => {
  console.log("yishengtuandui ", val.name);
  // emit("teamId", val);
  doctorsTeamName.value = val.name;
  postBasicDoctorByTeamId(val.id);
  doctorTeamInfo()
}
//获取医生
const postBasicDoctorByTeamId = async (teamId: string) => {
  const result = await api.Mdatastatistics.postBasicDoctorByTeamIdApi(teamId)
  // console.log("医生", result);
  doctorsLists.value = result.data.data
}


// 获取医生Id
const getdoctorId = (val: string) => {
  console.log("yishen ", val);
}

//传给签约业绩统计页面团队
const emit = defineEmits<{ (e: "doctorTeam", val: any): void }>()
const doctorTeamInfo = () => {
  // console.log("/", doctorsTeamName.value);
  emit("doctorTeam", doctorsTeamName.value)
}
</script>

<style lang='scss' scoped>
.select-box {
  display: flex;
  font-size: 12px;
  color: #999;

  .el-select {
    margin: 10px;
  }

  span {
    margin-left: 48px;
  }
}
</style>